<%
layout("/layouts/platform.html"){
%>
<section class="content-wrap bg-white">
    <header class="header navbar bg-white shadow">
<!--        <div class="btn-group tool-button">-->
<!--            <a id="add" class="btn btn-primary navbar-btn" href="${base}/platform/zs/complaint/add" data-pjax><i class="ti-plus"></i> ${msg['globals.button.add']}</a>-->
<!--            <button class="btn btn-danger navbar-btn" onclick="delCheck()"><i class="ti-close"></i> ${msg['globals.button.delete.more']}</button>-->
<!--        </div>-->
    </header>
    <div class=panel-body style="padding-top: 50px;">
        <div class="table-responsive no-border">
            <table class="table table-bordered table-striped mg-t datatable">
                <thead>
                    <tr>
                            <th>${msg['zs.complaint.column.complainantName']}</th>
                            <th>${msg['zs.complaint.column.complainantPhone']}</th>
                            <th>${msg['zs.complaint.column.content']}</th>
                            <th>${msg['zs.complaint.column.projectName']}</th>
                            <th>${msg['zs.complaint.column.status']}</th>
                            <th>${msg['zs.complaint.column.handling']}</th>
                            <th>${msg['zs.complaint.column.reason']}</th>
                            <th>${msg['zs.complaint.column.feedback']}</th>
                            <th>${msg['globals.table.column.operation']}</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</section>
<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">${msg['globals.button.delete']}</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        ${msg['globals.button.delete.notice']}
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">${msg['globals.button.cancel']}</button>
                <button id="okDel" type="button" class="btn btn-primary" data-loading-text="${msg['globals.button.delete.tip']}">${msg['globals.button.confirm']}</button>
            </div>
        </div>
    </div>
</div>
<div id="dialogDetail" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div>
    </div>
</div>
<script language="JavaScript">
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">frtip',
            "searching":false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/plugins/datatables/${lang}.json"
            },
            "preDrawCallback": function () {
                sublime.showLoadingbar($(".main-content"));
            },
            "drawCallback": function () {
                sublime.closeLoadingbar($(".main-content"));
            },
            "ajax": {
                "url": "${base}/platform/zs/complaint/dataHandle",
                "type": "post",
                "data": function (d) {

                }
            },
            "order": [[0, "desc"]],
            "columns": [
                    {"data": "complainantName", "bSortable": true,"defaultContent":""},
                    {"data": "complainantPhone", "bSortable": true,"defaultContent":""},
                    {"data": "content", "bSortable": true,"defaultContent":""},
                    {"data": "projectName", "bSortable": true,"defaultContent":""},
                    {"data": "status", "bSortable": true,"defaultContent":""},
                    {"data": "handling", "bSortable": true,"defaultContent":""},
                    {"data": "reason", "bSortable": true,"defaultContent":""},
                    {"data": "feedback", "bSortable": true,"defaultContent":""},
            ],
            "columnDefs": [
                {
                    "render": function (data, type, row) {
                        if(data== 0){
                            return "待受理";
                        }
                        if (data == 1) {
                            return "处理中";
                        }
                        if (data == -1) {
                            return "不处理";
                        }
                        if (data == 2) {
                            return "已处理";
                        }
                        if (data == 3) {
                            return "已反馈";
                        }
                    },
                    "targets":4,
                },
                {
                    "render": function (data, type, row) {
                        if (row.status ==0 ) {
                           return '<a class="btn btn-success  btn-xs " style="display: inline-block;margin-right: 5px"  onclick="accepting(\'' + row.id + '\');" data-toggle="modal">受理</a>' +
                                  '<a class="btn btn-success  btn-xs " href="${base}/platform/zs/complaint/detail/' + row.id + '" data-toggle="modal" data-target="#dialogDetail">详情</a>'
                        }
                        if(row.status ==1){
                           return '<a class="btn btn-success  btn-xs " style="display: inline-block;margin-right: 5px"  href="${base}/platform/zs/complaint/handlePage/'+ row.id + '" data-pjax>处理</a>'+
                               '<a class="btn btn-success  btn-xs " style="display: inline-block;margin-right: 5px"  href="${base}/platform/zs/complaint/noHandlePage/'+ row.id + '" data-pjax>不处理</a>'+
                               '<a class="btn btn-success  btn-xs " href="${base}/platform/zs/complaint/detail/' + row.id + '" data-toggle="modal" data-target="#dialogDetail">详情</a>'
                        }
                        if(row.status ==2){
                            return'<a class="btn btn-success  btn-xs " href="${base}/platform/zs/complaint/detail/' + row.id + '" data-toggle="modal" data-target="#dialogDetail">详情</a>'
                        }
                        if(row.status ==-1){
                            return'<a class="btn btn-success  btn-xs " href="${base}/platform/zs/complaint/detail/' + row.id + '" data-toggle="modal" data-target="#dialogDetail">详情</a>'
                        }
                        if(row.status ==3){
                            return'<a class="btn btn-success  btn-xs " href="${base}/platform/zs/complaint/detail/' + row.id + '" data-toggle="modal" data-target="#dialogDetail">详情</a>'
                        }

                    },
                    "targets": 8
                }
            ]
        });
        datatable.on('click', 'tr', function () {
            $(this).toggleClass('selected');
        });
        $("#searchBtn").on('click', function () {
            datatable.ajax.reload();
        });
    }
    function del(id) {
        var dialog = $("#dialogDelete");
        dialog.modal("show");
        dialog.find("#okDel").unbind("click");
        dialog.find("#okDel").bind("click", function (event) {
            var btn = $(this);
            btn.button("loading");
            $.post("${base}/platform/zs/complaint/delete/" + id, {}, function (data) {
                if (data.code == 0) {
                    datatable.ajax.reload(null,false);
                } else {
                    Toast.error(data.msg);
                }
                btn.button("reset");
                dialog.modal("hide");
            }, "json");
        });
    }

    //受理
    function accepting(data){
        $.ajax({
            type : "post",
            url : "${base}/platform/zs/complaint/accepting",
            data :{complaintId:data},
            async: false,
            success : function(data){
                Toast.success("受理成功！");
                datatable.ajax.reload();
            },
            error : function(data){
                Toast.error("受理失败！");
            }
        });
    }
    function delCheck() {
        var chks = datatable.rows('.selected').data();
        if (chks.length > 0) {
            var ids = [];
            $.each(datatable.rows('.selected').data(), function (i, n) {
                ids.push(n.id);
            });
            var dialog = $("#dialogDelete");
            dialog.modal("show");
            dialog.find("#okDel").unbind("click");
            dialog.find("#okDel").bind("click", function (event) {
                var btn = $(this);
                btn.button("loading");
                $.post("${base}/platform/zs/complaint/delete", {ids: ids.toString()}, function (data) {
                    if (data.code == 0) {
                        datatable.ajax.reload(null,false);
                    } else {
                        Toast.error(data.msg);
                    }
                    btn.button("reset");
                    dialog.modal("hide");
                }, "json");
            });
        } else {
            Toast.warning("${msg['globals.button.delete.select']}");
        }
    }
    $(function () {
        initDatatable();
        $("#dialogDetail").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
    });
</script>
<%}%>
